package client_commands;

import java.util.StringTokenizer;

import client.ClientApplication;
import client.ClientBindObject;

/**
 * Komanda koja se salje kao status aktivnosti (trenutnog pisanja poruke).
 * 
 * @author UrosKrkic & Radivoje Popovic
 */
public class PEER_TYPINGCommand extends Command {

	public PEER_TYPINGCommand(String parameter) {
		setCode(PEER_TYPING);
		setParameter(parameter);
	}


	@Override
	public boolean executeCommand(ClientApplication theApp) {
/*		
		System.out.println(getParameter());
		ClientBindObject cbo = ClientApplication.clientBinding.get(getParameter());
		
		if (cbo != null && cbo.getConnection() != null) {
			cbo.getConnection().setMessage(NO_BUFFERING, "PEER_TYPING " + getParameter());
			return true;
		}
*/
		if (getParameter() == null)
			return false;
		
		
		StringTokenizer tokens = new StringTokenizer(getParameter());
		
		if ( tokens.countTokens() != 2 ) {
			return false;
		}
		
		String username = tokens.nextToken();
		String typingFlag = tokens.nextToken();
		
		ClientBindObject cbo = ClientApplication.clientBinding.get(username);
		
		if ( cbo != null && cbo.getDialog() != null ) {
			if ( typingFlag.equals("true") )
				cbo.getDialog().showTyping();
			else
				cbo.getDialog().hideTyping();
		}
		
		return true;
	}

}
